var textField = function(config) {
	return new Ext.form.TextField(Ext.apply({
		xtype      : 'textfield',
		anchor     : '100%',
		listeners  : {
			change : function(field, newValue, oldValue ) {
				var form = this.findParentByType('form', true);
				if(form) {
					form.hasChanged = true;
				}
			}
		}
	}, config));
}

var dateField = function(config) {
	return new Ext.form.DateField(Ext.apply({
		xtype      : 'Datefield',
		anchor     : '100%',
		listeners  : {
			change : function(field, newValue, oldValue ) {
				var form = this.findParentByType('form', true);
				if(form) {
					form.hasChanged = true;
				}
			}
		}
	}, config));
}

var formPanel = function() {
	return new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 65,
        defaultType: 'textfield',
        hasChanged : false
    });
}

var positionComboBox = function(config) {
	return new Ext.form.ComboBox(Ext.apply({
		fieldLabel   : 'Position',
		displayField : 'name',
		valueField   : 'name',
		hiddenName   : 'position',
		emptyText    : 'Choose position ...',
		listeners  : {
			change : function(field, newValue, oldValue ) {
				var form = this.findParentByType('form', true);
				if(form) {
					form.hasChanged = true;
				}
			}
		},
		store        : new Ext.data.ArrayStore({
			data : [
				    ['Probationer'], ['Designer'], ['Test engineer'], ['Manager'], ['Line manager']
				],
			fields : [
			    {
			    	name : 'name'
			    }
			    ]
		}),
		mode           : 'local',
		triggerAction  : 'all',
		editable       : false,
		anchor         : '100%'	
	}, config));
}

function processErrors(result) {
	if('errors' in result) {
		var obj = result.errors[0];
		var errors = '';
	    for (var p in obj) {
	    	errors += obj[p] + '\n';
	    }
	    Ext.Msg.alert('ERROR', errors);
	} else {
		if('errorMessage' in result ) {
			Ext.Msg.alert('ERROR', result.errorMessage);
		} else {
			Ext.Msg.alert('ERROR', 'Unknown error occured');
		}
	}
}

CSViewerApp = {
	version : '1.0'
}

CSViewerApp.EventManager = new Ext.util.Observable();
CSViewerApp.EventManager.addEvents({
	'delete' : true
});